<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%
	String path = request.getContextPath() + "/";
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width,initial-scale=1,user-scalable=0">
<title>读者证绑定</title>
<link rel="stylesheet" href="css/weui.css" />
<link rel="stylesheet" href="css/example.css" />
<script src="js/jquery-1.9.1.js"></script>
</head>
<body>
	<img alt="" src="img/bind.png" width="100%">
	<div class="weui-cells weui-cells_form">
		<div class="weui-cell">
			<div class="weui-cell__hd">
				<label class="weui-label">读者证</label>
			</div>
			<div class="weui-cell__bd">
				<input class="weui-input" type="text" id="card"
					placeholder="请输入读者证号" />
			</div>
		</div>
		<div class="weui-cell">
			<div class="weui-cell__hd">
				<label class="weui-label">密码</label>
			</div>
			<div class="weui-cell__bd">
				<input class="weui-input" type="password" id="pass"
					placeholder="请输入密码" />
			</div>
		</div>
		<div class="weui-cell">
			<div class="weui-cell__hd">
				<label class="weui-label">机构</label>
			</div>
			<div class="weui-cell__bd">
				<select id="guid">
					<c:forEach var="g" items="${list }">
						<option value="${g.account }">${g.name }</option>
					</c:forEach>
				</select>
			</div>
		</div>
	</div>
	<div class="page__hd"></div>
	<div class="page__bd page__bd_spacing">
		<a href="javascript:;" class="weui-btn weui-btn_default"
			id="showToast">开始绑定</a>
	</div>

	<!--BEGIN toast-->
	<div id="toast" style="display: none;">
		<div class="weui-mask_transparent"></div>
		<div class="weui-toast">
			<i class="weui-icon-success-no-circle weui-icon_toast"></i>
			<p class="weui-toast__content">绑定成功！</p>
		</div>
	</div>
	<div id="toast2" style="display: none;">
		<div class="weui-mask_transparent"></div>
		<div class="weui-toast">
			<i class="weui-icon-warn weui-icon_toast"></i>
			<p class="weui-toast__content">用户名或密码错误！</p>
		</div>
	</div>
	<!--end toast-->

	<script type="text/javascript">
		var openid = '${openid}';
		var url = "http://www.xsdlib.com:8092/declaimer/wechat/bind";
		url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx56a412193b0453bb&redirect_uri='+url+'&response_type=code&scope=snsapi_userinfo#wechat_redirect';
		
		if(openid==''){
			window.location.href=url;
		}
		// toast
		$(function() {
			var $toast = $('#toast');
			var $toast2 = $('#toast2');
			$('#showToast').on('click', function() {
				var flag = false;
				var card = $("#card").val();
				var pass = $("#pass").val();
				var guid = $("#guid").val();
				$.ajax({
					type : "POST",
					url : "user/login",
					dataType : "json",
					data : {
						"card" : card,
						"passwd" : pass,
						"openid" : '${openid}',
						"guid" : guid
					},
					success : function(data) {
						if (data.msg == "ok")
							flag = true;

						if (flag) {
							if ($toast.css('display') != 'none')
								return;
							$toast.fadeIn(100);
							setTimeout(function() {
								$toast.fadeOut(100);
								location.href = "reader";

							}, 2000);

						} else {
							if ($toast2.css('display') != 'none')
								return;
							$toast2.fadeIn(100);
							setTimeout(function() {
								$toast2.fadeOut(100);
							}, 2000);

						}

					}
				});

			});
		});
	</script>
	<br>
	<div class="weui-footer">
		<p class="weui-footer__links">
		</p>
		<p class="weui-footer__text">Copyright &copy; 2017-2022
			信昇达物联科技有限公司</p>
	</div>
</body>
</html>
